﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Resources;
using System.Globalization;

namespace LPV_POS.mh_pos
{
    public partial class mh_dmgiamgia : DevExpress.XtraEditors.XtraForm
    {
        CultureInfo culture;
        #region "Muti language"

        private void SetLanguage_banhang(string cultureName)
        {
            try
            {
                culture = CultureInfo.CreateSpecificCulture(cultureName);
                ResourceManager rm = new ResourceManager("LPV_POS.Muti_language.MyResource", typeof(mh_banhang6_PhuThu).Assembly);
                
                this.col_OBJNAME.Caption = rm.GetString("ten", culture);
                this.col_GIATRI.Caption = rm.GetString("giatri", culture);
                simpleButton1.Text = rm.GetString("dongy", culture);
                simpleButton2.Text = rm.GetString("thoat", culture);
                rbtGiam_An.Text = rm.GetString("giamthucan", culture);
                rbtGiam_Uong.Text = rm.GetString("giamthucuong", culture);
                rbtGiam_ThucAnUong.Text = rm.GetString("giammondangchon", culture);
                rbtGiam_HoaDon.Text = rm.GetString("giamtongthucdon", culture);
                this.Name = rm.GetString("giamgia", culture);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Note");
            }

        }

        #endregion
        public mh_dmgiamgia()
        {
            InitializeComponent();
            culture = CultureInfo.CurrentCulture;
        }
        DataTable tbMain = null;
        private void mh_dmgiamgia_Load(object sender, EventArgs e)
        {
            cpublic ocpublic = new cpublic();
            string str_lang = ocpublic.Registry_Get("mh_main_lang");
            if (str_lang == "")
                str_lang = "vi-VN";
            SetLanguage_banhang(str_lang);

            string sSQL = "SELECT STT = ROW_NUMBER() OVER (ORDER BY OBJID)%2, OBJID, MA_LOAI_GIAMGIA, OBJNAME, GIATRI FROM DM_GIAMGIA";
            tbMain = new thuvien().SP_SelectDataTable("SP_EXECUTESQL", new string[] { "@sSQL" }, new object[] { sSQL });
            //grdGiamGia.DataSource = tbMain;
            this.btnGiam_anuong_Click(btnGiam_anuong, null);
            
        }

        private void btnGiam_anuong_Click(object sender, EventArgs e)
        {
           
            tbMain.DefaultView.RowFilter = ((SimpleButton)sender).Tag+"";
            grdGiamGia.DataSource = tbMain.DefaultView;
            
        }
        DataRow drMain = null;
        public DataRow ShowForm()
        {//form khac gọi đến form này
            this.ShowDialog();

            return drMain;
        }

        private void simpleButton2_Click(object sender, EventArgs e)
        {//CLOSE
            drMain = null;
            this.Dispose();
        }

        private void simpleButton1_Click(object sender, EventArgs e)
        {//SELECT//form khac gọi đến form này
            object odr = gridView1.GetRow(gridView1.FocusedRowHandle);
            if (odr != null)
            {
                drMain = ((DataRowView)odr).Row;
                this.Close();
            }
        }

        private void rbtGiam_AnUong_CheckedChanged(object sender, EventArgs e)
        {
            tbMain.DefaultView.RowFilter = ((System.Windows.Forms.Control)sender).Tag + "";
            grdGiamGia.DataSource = tbMain.DefaultView;
        }

       
    }
}